package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public interface DishMapper {
    @Select("SELECT count(id) FROM dish where category_id=#{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 新增菜品
     *
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void saveDish(Dish dish);

    /**
     * 菜品分页查询
     *
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据id删除菜品
     *
     * @param id
     */
    void deleteDish(Long id);

    /**
     * 查询菜品状态
     *
     * @param id
     * @return
     */
    @Select("SELECT status FROM dish where id=#{id}")
    Integer selectDishStatus(Long id);

    /**
     * 根据id回显
     *
     * @param id
     * @return
     */
    DishVO getById(Long id);

    /**
     * 修改菜品
     *
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);

    /**
     * 菜品起售停售
     *
     * @param id,status
     */
    @AutoFill(OperationType.UPDATE)
    void updateDishStatus(String status, Long id);

    /**
     * 根据分类id查询菜品
     *
     * @param categoryId
     * @return
     */
    List<DishVO> list(Long categoryId);
}
